package com.kgc.novel.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @author mac
 * 通用响应结果类
 */
@Data
public class Res<T> implements Serializable {


    private static final long serialVersionUID = 1L;
    /**
     * 状态码
     */
    private int code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 响应对象
     */
    private T data;

    /**
     * 总数
     */
    private Long total;

    private Res(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Res(int code, String msg, T data) {
        this(code, msg);
        this.data = data;
    }

    private Res(int code, String msg, T data, Long total) {
        this(code, msg, data);
        this.total = total;
    }

    public static <T> Res<T> returnMsg(String msg) {
        return new Res<>(0, msg);
    }

    public static <T> Res<T> returnData(String msg, T data, Long total) {
        return new Res<>(0, msg, data, total);
    }

    public static <T> Res<T> returnData(String msg, T data) {
        return new Res<>(0, msg, data);
    }

    public static <T> Res<T> returnData(T data, Long total) {
        return new Res<>(0, "ok！", data, total);
    }

    public static <T> Res<T> returnData(T data) {
        return new Res<>(0, "ok！", data);
    }

    public static <T> Res<T> returnErrMsg(String msg) {
        return new Res<>(1, msg);
    }

    public static <T> Res<T> returnErr() {
        return new Res<>(2, "系统异常！");
    }

    public static <T> Res<T> returnTokenErr(String msg) {
        return new Res<>(3, msg);
    }

    public static <T> Res<T> returnTokenErr() {
        return new Res<>(4, "token失效,请重新获取");
    }

    public static <T> Res<T> returnUploadErr(String msg) {
        return new Res<>(5, msg);
    }

}
